<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="common/common_head :: commonHeader('供应商配额录入')"/>
    <link th:href="@{/static/css/plugins/cropper/cropper.min.css}" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form class="form-horizontal" method="post" id="quotaForm">
        <div class="row">
            <div class="form-group">
                <div class="col-sm-8" style="margin-left: 16px">
                    <input class="btn btn-primary" type="button" onclick="save()" value="保存">
                    <button class="btn btn-primary" type="button" onclick="Dialog.closeFrame(window.name)">取 消</button>
                </div>
            </div>
            <!-- 基本信息 -->
            <div id="basicinformation">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-xs-1 control-label"><span class="required-sign">*</span>供应商编码：</label>
                            <div class="col-xs-3">
                                <input name="quotaId" th:value="${quotaEntity.quotaId}" type="hidden"
                                       readonly="readonly" class="form-control">
                                <input name="vendorCode" th:value="${quotaEntity.vendorCode}" type="text"
                                       readonly="readonly" class="form-control">
                            </div>
                            <label class="col-xs-1 control-label">供应商名称：</label>
                            <div class="col-xs-3">
                                <input name="vendorName" th:value="${quotaEntity.vendorName}" type="text"
                                       readonly="readonly" class="form-control">
                            </div>
                            <label class="col-xs-1 control-label"><span class="required-sign">*</span>配额数：</label>
                            <div class="col-xs-3">
                                <input id="quotaNum" name="quotaNum" th:value="${quotaEntity.quotaNum}" type="number"
                                       class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>物料号：</label>
                            <div class="col-xs-3">
                                <input name="materialCode" th:value="${quotaEntity.materialCode}" type="text"
                                       readonly="readonly" class="form-control">
                            </div>
                            <label class="col-sm-1 control-label">物料描述：</label>
                            <div class="col-xs-3">
                                <input name="materialDesc" th:value="${quotaEntity.materialDesc}" type="text"
                                       readonly="readonly" class="form-control">
                            </div>
                            <label class="col-xs-1 control-label">已分配数量：</label>
                            <div class="col-xs-3">
                                <input id="usedQuotaNum" th:value="${quotaEntity.usedQuotaNum}" type="text"
                                       class="form-control" disabled>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>开始时间：</label>
                            <div class="col-xs-3">
                                <input id="startDate" name="startDate"
                                       th:value="${#dates.format(quotaEntity.startDate,'yyyy-MM-dd')}" type="text"
                                       class="form-control" autocomplete="off">
                            </div>
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>结束时间：</label>
                            <div class="col-xs-3">
                                <input id="endDate" name="endDate"
                                       th:value="${#dates.format(quotaEntity.endDate,'yyyy-MM-dd')}" type="text"
                                       class="form-control" autocomplete="off">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Chosen -->
<script th:src="@{/static/js/plugins/chosen/chosen.jquery.js}"></script>
<script type="text/javascript">

    // 初始化时间插件
    laydate.render({elem: '#startDate'});
    laydate.render({elem: '#endDate'});

    //判断开始时间与结束时间是否有值
    $(function () {
        var startData = $("#startDate").val();
        var endData = $("#endDate").val();
        if (startData.length !== 0 || endData.length !== 0) {
            $("#startDate").attr("disabled", true);
            $("#endDate").attr("disabled", true);
        }
    });

    //保存
    function save() {

        let usedQuotaNum = $("#usedQuotaNum").val();
        let quotaNum = $("#quotaNum").val();
        if (quotaNum < usedQuotaNum) {
            Dialog.errorMsg("配额数不能小于已用配额数量！");
            return false;
        }

        layer.load(1, {shade: [0.3, '#393D49']});
        if ($("#quotaForm").valid()) {
            Page.ajaxPOST(ctxPath + "/quota/save", $('#quotaForm').serialize(), function (res) {
                Dialog.msg("新增成功!", function () {
                    parent.refresh();
                    Dialog.closeFrame(window.name);
                });
                layer.closeAll();
            });
        }
    }
</script>

</body>
</html>
